package org.example.manage.impl;

import org.example.manage.ShoppingUserManage;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Component
public class ShoppingUserManageImpl implements ShoppingUserManage {

    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    @Override
    public void addToken(String key, String token, Long ttl) {
            redisTemplate.opsForValue().setIfAbsent(key,token,ttl, TimeUnit.SECONDS);
    }

    @Override
    public String getToken(String key) {
        return  (String)redisTemplate.opsForValue().get(key);
    }

    @Override
    public void removeToken(String key) {
        redisTemplate.delete(key);

    }
}
